package sort;

import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
import java.util.Random;
import java.util.SimpleTimeZone;

public class InsertSort {
    public static void main(String[] args) {
        int[] arr = new int[200000];
        for (int i = 0; i < 200000; i++) {
            arr[i]=(int)(Math.random()*8000000);

        }
        System.out.println("排序前");
        Date date = new Date();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yy-MM-dd HH:mm:ss");
        String str=simpleDateFormat.format(date);
        System.out.println("排序前："+str);
        sort(arr);
        Date d2 = new Date();
        String str1=simpleDateFormat.format(d2);
        System.out.println("排序后"+str1);
     /*   int[] arr = new int[80000];
        Random random = new Random(47);
        for (int i = 0; i < 80000; i++) {
            arr[i]=random.nextInt(100);
        }
        long l1= System.currentTimeMillis();
        sort(arr);
        long l2= System.currentTimeMillis();
        System.out.println(l2-l1);*/
    }

    public static void sort(int[] arr) {
        int index ;
        int indexVal ;
        for (int i = 1; i < arr.length; i++) {
            indexVal =arr[i];
            index = i-1;
            while(index >= 0 && indexVal< arr[index]){
                arr[index+1]=arr[index];
                index--;
            }
            arr[index+1]=indexVal;
        }

    }
}
